package com.sdwl.brcl.validation.validation;

/**
 * @author xied
 * @date 2021年06月11日 14:02
 */
public class BooleanValidator implements Validator {
    public static final int FALSE = 0;
    public static final int TRUE = 1;
    private int type;

    public BooleanValidator(int type) {
        this.type = type;
    }

    @Override
    public boolean validate(Object value) {
        if (value == null) {
            return false;
        } else if (this.type == 0) {
            return !(Boolean)value;
        } else {
            return this.type == 1 ? (Boolean)value : false;
        }
    }

    @Override
    public String validateCode() {
        return this.type == 0 ? "not.eq.false" : "not.eq.true";
    }

    @Override
    public String validateMsg(Object value, String validateName) {
        if (this.type == 0) {
            return validateName + "必须为false";
        } else {
            return this.type == 1 ? validateName + "必须为true" : "";
        }
    }
}
